<?php
/*
 * 		File: weathercron.php
 * 		Author: Sasa Milojevic
 * 		Date: 2012-02-03
 * 		Desc: Cron Job Controller za update-ovanje vremena za Yahoo-a
 * 
 */
require_once($application_folder."/controllers/navigator.php");
class WeatherCron extends Navigator{

	private $_dbTable = 'weather_cron';
	
    function __construct(){
        parent::__construct();
        
        // Load Library Weather
        $this->load->library('weather',array('loc' => 'MWXX0001'));
        // Initialize library Weather                                       
        $this->weather->initialize();
    }
	

    public function index()
    {
    	show_404();
    }
    
   
     
    public function cron()
    {
    	$img = $this->weather->img();
    	$img_array= explode("/",$img );
    	$img_name = substr($img_array[8],0,strlen($img_array[8])-4 ) . "png";
 
    	
    	$sql = "INSERT INTO `{$this->_dbTable}` SET 
    				`datetime` = ".time().",
    				`tmin` = ".$this->weather->tmin().",
    				`tmax` = ".$this->weather->tmax().",
    				`hmd`  = ".$this->weather->hmd().",
    				`pre`  = ".$this->weather->pre().",
    				`img_full`  = '".$img."',
    				`img_name`	= '".$img_name."'
    			;";
    	//echo $sql;
    	if($this->db->query($sql)) echo "Query affected: ".$this->db->affected_rows(). " row(s).";
    	else	echo "Query failed;";
    }
    
}